package cn.edu.zafu.bigdata.x.zyy;

import java.util.List;

public class GenericMaxFinder{
    public static <T extends Comparable<T>> T findMax(List<T> list) {
        if (list == null || list.isEmpty()) {
            return null;
        }
        T max = list.get(0);
        for (T element : list) {
            if (element.compareTo(max) > 0) {
                max = element;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        // 测试整数列表
        java.util.ArrayList<Integer> intList = new java.util.ArrayList<>();
        intList.add(5);
        intList.add(3);
        intList.add(8);
        Integer maxInt = findMax(intList);
        System.out.println("整数列表中的最大值: " + maxInt);

        // 测试字符串列表
        java.util.ArrayList<String> stringList = new java.util.ArrayList<>();
        stringList.add("apple");
        stringList.add("banana");
        stringList.add("cherry");
        String maxString = findMax(stringList);
        System.out.println("字符串列表中的最大值: " + maxString);
    }
}